﻿#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<windows.h>


void menu()
{
	printf("************************************************************************************************************************\n");
	printf("**********************************************     1. play     *********************************************************\n");
	printf("**********************************************     0. exit     *********************************************************\n");
	printf("************************************************************************************************************************\n");
	
}


void game()
{
	int r = rand() % 100 + 1;
	int count = 5;
	int guess = 0;
	while (count)
	{
		printf("\nYou have only %d opportunities\n", count);
		printf("Please guess the number:");
		scanf("%d", &guess);
		if (guess < r)
		{
			printf("Smaller\n");
		}
		else if (guess > r)
		{
			printf("Bigger\n");
		}
		else
		{
			printf("Congratulations!You are right!\n");
			break;
		}count--;
	}
	if (count == 0)
	{
		printf("You are lose,the right number is %d", r);
	}
}


int main()
{
	printf("请仔细阅读以下游戏规则：\n");
	printf("玩家需输入1~100中任意一个数字，来猜取电脑给出的任意数字，猜大或猜小系统会给出对应提示，共有5次机会\n");
	int input = 0;
	srand((unsigned int)time(NULL));
	do
	{
		menu();
		printf("Please choose--->  ");
		scanf("%d", &input);
		switch (input)
		{
		case 1:
			game();
			break;
		case 0:
			printf("You are already exit the game\n");
			break;
		default:
			printf("Choose wrong,please choose again\n");
			break;
		}
		Sleep(7000);
		system("cls");
	} while (input);

	return 0;
}